package com.design.controller.web;

import com.design.model.*;
import com.design.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@Api(tags = "【WEB端-用户管理】")
@RequestMapping("/manager")
@CrossOrigin(origins = "*")
public class ManagerController {

    @Autowired
    private ManageService manageService;

    /**
     * 查询用户列表
     *
     * @param name     用户名
     * @param gender   性别
     * @param pageNum  页序号
     * @param pageSize 页大小
     * @return 用户列表
     */
    @ApiOperation(value = "用户管理-查询用户列表")
    @GetMapping("/queryByPage")
    public PageResult<List<UserInfoResponse>> queryByPage(String carNum, byte userType, String name, Integer gender, Integer pageNum, Integer pageSize) {
        return manageService.queryByPage(carNum, userType, name, gender, pageNum, pageSize);
    }

    /**
     * 删除用户
     *
     * @param id 用户id
     * @return 删除结果
     */
    @ApiOperation(value = "用户管理-删除用户")
    @GetMapping("/deleteById")
    public BaseResult<Void> deleteById(long id) {
        manageService.deleteById(id);
        return new BaseResult<>();
    }

    /**
     * 添加用户
     *
     * @param userInfoRequest 用户信息
     */
    @ApiOperation(value = "用户管理-添加用户/更新用户")
    @PostMapping("/edit")
    public BaseResult<Void> saveUser(@RequestBody UserInfoRequest userInfoRequest) {
        manageService.saveUser(userInfoRequest);
        return new BaseResult<>();
    }

    /**
     * 修改密码
     *
     * @param request 密码
     * @return 修改结果
     */
    @ApiOperation(value = "用户管理-修改密码")
    @PostMapping("/updatePassword")
    public BaseResult<Void> updatePassword(@RequestBody UserInfoUpdateRequest request) {
        manageService.updatePassword(request);
        return new BaseResult<>();
    }
}
